package com.xzcedu.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 徐州城
 * @version 1.0
 */
public class RegExp05 {
    public static void main(String[] args) {
        String content = "1111111Xxaaaaaaa";
        //String regStr = "a{3,}"; //匹配 aaa
        //String regStr = "\\d{2}"; //两位任意数字字符

        //细节: java匹配默认贪婪匹配，尽可能匹配多的
        //String regStr = "a{3,4}"; //要求匹配aaa或aaaa

        //1+
        //String regStr = "1+"; //匹配1或多个

        //1*
        //String regStr = "1*"; //匹配0或多个

        //1?
        String regStr = "a1?"; //匹配0或1个

        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);

        while (matcher.find()){
            System.out.println("找到: " + matcher.group(0));
        }
    }
}
